import { MigrationInterface, QueryRunner, Table, Index } from 'typeorm';

export class CreateMasterCategoryTable20250210000000 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.createTable(
      new Table({
        name: 'master_categories',
        columns: [
          {
            name: 'id',
            type: 'int',
            isPrimary: true,
            isGenerated: true,
            generationStrategy: 'increment',
          },
          {
            name: 'name',
            type: 'varchar',
            length: '50',
            comment: '母分类名称',
          },
          {
            name: 'keywords',
            type: 'varchar',
            length: '200',
            comment: '推荐关键词',
          },
          {
            name: 'status',
            type: 'tinyint',
            default: 1,
            comment: '状态: 0-禁用 1-启用',
          },
          {
            name: 'description',
            type: 'text',
            isNullable: true,
            comment: '分类描述',
          },
          {
            name: 'sortOrder',
            type: 'int',
            default: 0,
            comment: '排序权重',
          },
          {
            name: 'createdAt',
            type: 'timestamp',
            default: 'CURRENT_TIMESTAMP',
          },
          {
            name: 'updatedAt',
            type: 'timestamp',
            default: 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
          },
        ],
      }),
      true,
    );

    // 索引创建暂时跳过，可以通过其他方式创建
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.dropTable('master_categories');
  }
}